package com.finger.forest.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.finger.forest.R;
import com.finger.forest.model.NoticeItemModel;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.List;

/**
 * @author sy
 * @date 2021/1/19
 * @desc
 */
public class NoticeItemAdapter extends BaseQuickAdapter<NoticeItemModel, BaseViewHolder> {
    public NoticeItemAdapter(int layoutResId, @Nullable List<NoticeItemModel> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, NoticeItemModel item) {
        CheckBox cbNotice = helper.getView(R.id.cbNotice);
        if (item.isShowCheck()) {
            cbNotice.setVisibility(View.VISIBLE);
            cbNotice.setChecked(false);
        } else {
            cbNotice.setVisibility(View.GONE);
        }

        //消息内容
        TextView tvDesc = helper.getView(R.id.tvDesc);
        tvDesc.setText(item.getCreateBy());

        //类型图片
        RoundedImageView rivNotice = helper.getView(R.id.rivNotice);
        int type = item.getNoticeType();
        switch (type) {
            case 1:
                rivNotice.setBackgroundResource(R.mipmap.icon_common_alarm);
                break;

            case 2:
                rivNotice.setBackgroundResource(R.mipmap.icon_common_alarm);
                break;

            //人工报警
            case 3:
                rivNotice.setBackgroundResource(R.mipmap.icon_manual_alarm);
                tvDesc.setText("报警人:" + item.getCreateBy());
                break;

            //热点报警
            case 4:
                rivNotice.setBackgroundResource(R.mipmap.icon_hot_spot_alarm);
                tvDesc.setText("报警热点:" + item.getCreateBy());
                break;

            //热点报警
            case 5:
                rivNotice.setBackgroundResource(R.mipmap.icon_hot_spot_alarm);
                tvDesc.setText("报警人:" + item.getCreateBy());
                break;

            //热点报警
            case 6:
                rivNotice.setBackgroundResource(R.mipmap.icon_base_station_alarm);
                tvDesc.setText("报警人:" + item.getCreateBy());
                break;
        }

        //是否置顶
        ImageView tvIsTop = helper.getView(R.id.tvIsTop);
        //0 是 1 否
        int specify = item.getSpecify();
        if (specify == 0) {
            tvIsTop.setVisibility(View.VISIBLE);
        } else {
            tvIsTop.setVisibility(View.INVISIBLE);
        }

        //是否可读
        TextView tvIsRead = helper.getView(R.id.tvIsRead);
        //0 未读 1 已读
        int readingStatus = item.getReadingStatus();
        if (readingStatus == 0) {
            tvIsRead.setVisibility(View.VISIBLE);
        } else {
            tvIsRead.setVisibility(View.INVISIBLE);
        }

        //消息标题
        TextView tvNoticeTitle = helper.getView(R.id.tvNoticeTitle);
        tvNoticeTitle.setText(item.getNoticeTitle());

        //时间
        TextView tvNoticeTime = helper.getView(R.id.tvNoticeTime);
        tvNoticeTime.setText(item.getCreateTime());

        //是否选中
        cbNotice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    item.setSelect(true);
                } else {
                    item.setSelect(false);
                }
            }
        });
    }
}
